//
//  YMTabBarController.swift
//  swift_review
//
//  Created by Andrew on 2024/11/24.
//

import UIKit

class YMTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewControllers()
    }

    //添加子控制器
    func addChildViewControllers() {
        setChildViewController(ViewController(), title: "我的", imageName: "icon_tab_equipment_nor", selectImage: "icon_tab_equipment_sel")
    }
    
    //初始化子控件
    func setChildViewController(_ childController: UIViewController, title: String, imageName: String, selectImage: String) {
        // 设置tabbar文字和图片
        childController.tabBarItem.title = title
        childController.tabBarItem.selectedImage = UIImage(named: selectImage)
        childController.tabBarItem.image = UIImage(named: imageName)
        //添加导航控制器为tabbarController的自控制器
        let navVC = YMNavigationController(rootViewController: childController)
        addChild(navVC)
    }
    
    //添加tabbar文字属性
    func setUpTitleTextAttributes() {
        let item = UITabBarItem.appearance()
        var normalAttrs: [NSAttributedString.Key: Any] = [:]
        normalAttrs[NSAttributedString.Key.font] = UIFont.systemFont(ofSize: 12)
        normalAttrs[NSAttributedString.Key.foregroundColor] = UIColor.gray
        item.setTitleTextAttributes(normalAttrs, for: .normal)
        
        var selectedAttrs: [NSAttributedString.Key: Any] = [:]
        selectedAttrs[NSAttributedString.Key.foregroundColor] = UIColor.black
        item.setTitleTextAttributes(selectedAttrs, for: .selected)
    }
}
